package org.dromara.system.service.impl;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.utils.BeanCopyUtils;
import org.dromara.system.mapper.SysTenantPackageMapper;
import org.dromara.system.pojo.bo.SysTenantPackageBO;
import org.dromara.system.pojo.entity.SysTenantPackageDO;
import org.dromara.system.pojo.qo.SysTenantPackageQO;
import org.dromara.system.pojo.vo.SysTenantPackageVO;
import org.dromara.system.service.SysTenantPackageService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 租户套餐表 服务层实现。
 *
 * @author mkj
 * @since 2024-07-21
 */
@RequiredArgsConstructor
@Service
public class SysTenantPackageServiceImpl implements SysTenantPackageService {

    private final SysTenantPackageMapper sysTenantPackageMapper;

    @Override
    public boolean add(SysTenantPackageBO sysTenantPackageBO) {
        SysTenantPackageDO sysTenantPackageDO = BeanCopyUtils.copy(sysTenantPackageBO, SysTenantPackageDO.class);
        return sysTenantPackageMapper.insert(sysTenantPackageDO) > 0;
    }

    @Override
    public boolean remove(Long id) {
        return sysTenantPackageMapper.deleteById(id) > 0;
    }

    @Override
    public boolean update(SysTenantPackageBO sysTenantPackageBO) {
        SysTenantPackageDO sysTenantPackageDO = BeanCopyUtils.copy(sysTenantPackageBO, SysTenantPackageDO.class);
        return sysTenantPackageMapper.update(sysTenantPackageDO) > 0;
    }

    @Override
    public List<SysTenantPackageVO> list(SysTenantPackageQO sysTenantPackageQO) {
        SysTenantPackageDO sysTenantPackageDO = BeanCopyUtils.copy(sysTenantPackageQO, SysTenantPackageDO.class);
        QueryWrapper queryWrapper = QueryWrapper.create(sysTenantPackageDO);
        return sysTenantPackageMapper.selectListByQueryAs(queryWrapper, SysTenantPackageVO.class);
    }

    @Override
    public SysTenantPackageVO getInfo(Long id) {
        SysTenantPackageDO sysTenantPackageDO = sysTenantPackageMapper.selectOneById(id);
        if (sysTenantPackageDO == null) {
            return null;
        }
        return BeanCopyUtils.copy(sysTenantPackageDO, SysTenantPackageVO.class);
    }

    @Override
    public Page<SysTenantPackageVO> page(SysTenantPackageQO page) {
        return sysTenantPackageMapper.paginateAs(page.getPageNumber(), page.getPageSize(), QueryWrapper.create(page), SysTenantPackageVO.class);
    }

}

